package com.example.hp.yuejian5.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.hp.yuejian5.R;
import com.example.hp.yuejian5.RetrofitListener.RetrofitListener;
import com.example.hp.yuejian5.bean.ShowBean;
import com.example.hp.yuejian5.model.Show_DetailModel;
import com.squareup.picasso.Picasso;

import static com.example.hp.yuejian5.other.url.PICTURE;

public class Show_DetailActivity extends AppCompatActivity {
    private String i_id, u_id;
    private Context context;
    private RetrofitListener<ShowBean> listener;

    private ImageView show_detail_pic;
    private SharedPreferences sp;
    private TextView show_detail_content, show_detail_time, show_detail_title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_show_detail);
        Intent intent = getIntent();
        i_id = (String) intent.getStringExtra("p_id");
        sp = getSharedPreferences("user_id", Context.MODE_PRIVATE);
        u_id = sp.getString("userid", null);
        initView();

        listener = new RetrofitListener<ShowBean>() {
            @Override
            public void onSuccess(ShowBean showBean, int flag) {
                show_detail_content.setText(showBean.getPicture_content());
                show_detail_time.setText(showBean.getPicture_time());
                show_detail_title.setText(showBean.getPicture_title());
                Picasso.with(context).load(PICTURE + showBean.getPicture_pic()).into(show_detail_pic);
            }

            @Override
            public void onFail() {

            }
        };


        showDetail();

    }

    private void initView() {
        show_detail_pic = findViewById(R.id.show_detail_pic);
        show_detail_content = findViewById(R.id.show_detail_content);
        show_detail_time = findViewById(R.id.show_detail_time);
        show_detail_title = findViewById(R.id.show_detail_title);
    }


    private void showDetail() {
        Show_DetailModel show_detailModel = new Show_DetailModel();
        show_detailModel.showDetail(i_id, listener);
    }



}
